<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

/**
 * AmaotoUser
 *
 * @property integer $id
 * @property string $username
 * @property string $email
 * @property string $password
 * @property integer $power
 * @property string $reg_ip
 * @property integer $reg_time
 * @property string $login_ip
 * @property integer $login_time
 * @property string $act_ip
 * @property integer $act_time
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property \Carbon\Carbon $deleted_at
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereUsername($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereEmail($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser wherePassword($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser wherePower($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereRegIp($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereRegTime($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereLoginIp($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereLoginTime($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereActIp($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereActTime($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereDeletedAt($value)
 * @property string $remember_token
 * @method static \Illuminate\Database\Query\Builder|\AmaotoUser whereRememberToken($value)
 */
class AmaotoUser extends Eloquent implements UserInterface, RemindableInterface
{

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password');

    use Illuminate\Database\Eloquent\SoftDeletingTrait;

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the token value for the "remember me" session.
     *
     * @return string
     */
    public function getRememberToken()
    {
        return $this->remember_token;
    }

    /**
     * Set the token value for the "remember me" session.
     *
     * @param  string $value
     * @return void
     */
    public function setRememberToken($value)
    {
        $this->remember_token = $value;
    }

    /**
     * Get the column name for the "remember me" token.
     *
     * @return string
     */
    public function getRememberTokenName()
    {
        return 'remember_token';
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }

    public function isAdmin()
    {
        return $this->power >= 99999 ? true : false;
    }

    public function updateAct()
    {
        $this->act_ip   = Input::getClientIp();
        $this->act_time = time();
        $this->save();
    }

    public function updateLogin()
    {
        $this->login_ip   = Input::getClientIp();
        $this->login_time = time();
        $this->act_ip     = Input::getClientIp();
        $this->act_time   = time();
        $this->save();
    }
}